package com.bangdream.michelia.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bangdream.michelia.R;
import com.bangdream.michelia.entity.TeacherBean;
import com.bangdream.michelia.tool.CircleImageView;
import com.bangdream.michelia.utils.ImageLoadUtils;

import java.util.List;

/**
 * @date on 2018/7/19 14:40
 * @email 909732184@qq.com
 * 精英讲师列表适配器
 */
public class EliteLecturerAdapter extends RecyclerView.Adapter {
    private Context context;
    private LayoutInflater inflater;
    private OnItemClickListener onItemClickListener;
    private List<TeacherBean> data;
    public OnItemClickListener getOnItemClickListener() {
        return onItemClickListener;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public void setData(List<TeacherBean> data) {
        this.data = data;
    }

    public List<TeacherBean> getData() {
        return data;
    }

    public interface OnItemClickListener{
        void onItemClick(int position);
    }
    public EliteLecturerAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.elitelecturer_adapter_item,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof ViewHolder){
            ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.position = position;

            TeacherBean bean = data.get(position);
            ImageLoadUtils.ImageLoad(context,bean.getFaceUrl(),viewHolder.ivLogo,-1);
            viewHolder.tvName.setText(bean.getName()+"");
            viewHolder.tvDescribe.setText(Html.fromHtml(bean.getContent()+""));
        }
    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder{
        private int position;
        private CircleImageView ivLogo;
        private TextView tvName;
        private TextView tvDescribe;
        private ImageView ivMedal;
        private ImageView ivLv;
        public ViewHolder(View itemView) {
            super(itemView);
            ivLogo = itemView.findViewById(R.id.ivLogo);
            ivLogo.setmBorderWidth(10);
            tvName = itemView.findViewById(R.id.tvName);
            tvDescribe = itemView.findViewById(R.id.tvDescribe);
            ivMedal = itemView.findViewById(R.id.ivMedal);
            ivLv = itemView.findViewById(R.id.ivLv);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onItemClickListener!=null){
                        onItemClickListener.onItemClick(position);
                    }
                }
            });
        }
    }
}
